<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="w" tagdir="/WEB-INF/tags" %>
<%!
	final String[][] totalName = {
			{"수입: ", "저축: ", "총지출: "},
			{"지출: ", "저축: ", "총수입: "},
			{"수입: ", "지출: ", "총저축: "}
	};
%>

<div class="grid_wrap">
	<div class="grid_title">
		<table cellpadding="0" cellspacing="0">
			<col style="width: 27px;"/>
			<col style="width: 60px;"/>
			<col style=""/>
			<col style="width: 110px;"/>
			<col style="width: 110px;"/>
			<col style="width: 120px;"/>
			<col style="width: 166px;"/>
			<tbody>
				<tr>
					<td class="grid_tab_title"><input type="checkbox" id="all-check"/></td>
					<td class="grid_tab_title">날짜</td>
					<td class="grid_tab_title">사용내역</td>
					<td class="grid_tab_title">현금</td>
					<td class="grid_tab_title disabled">카드</td>
					<td class="grid_tab_title disabled">카드종류</td>
					<td class="grid_tab_title">분류</td>		
				</tr>		
			</tbody>
		</table>
	</div>
		
	<div class="grid_panel">
		<table id="grid_table" cellpadding="0" cellspacing="0">
			<c:set var="column">
				<col style="width: 27px;"/>
				<col style="width: 60px;"/>
				<col style=""/>
				<col style="width: 110px;"/>
				<col style="width: 110px;"/>
				<col style="width: 120px;"/>
				<col style="width: 150px;"/>
			</c:set>
			<c:out value="${column}" escapeXml="false"/>
			<tbody>
			
			<c:forEach items="${list}" var="i">
			<c:choose>
			<c:when test="${param.tab==i.tab}">	
				<tr class="_${i.seq}">
					<td class="seq"><input type="checkbox" class="_${i.seq}"/></td>
					<td class="yyyymmdd"><w:date date="${i.date}"/></td>
					<td class="description">${i.description}</td>
					<td class="cash numbertd">${i.cash}</td>
					<td class="card numbertd disabled">${i.card}</td>
					<c:set var="cashTotal" value="${cashTotal+i.cash}"/>
					<c:set var="cardTotal" value="${cardTotal+i.card}"/>
					<td class="cardtype disabled"><span class="cardtype_${i.cardtype}">${card[i.cardtype]}</span></td>
					<td class="cate"><span class="cate_${i.category}"><w:Category category="${i.category}"/></span></td>	
				</tr>
			</c:when>
			<c:when test="${param.tab!=1}">
				<c:choose>
				<c:when test="${i.tab==1}"><c:set var="leftTotal" value="${leftTotal+i.cash+i.card}"/></c:when>
				<c:otherwise><c:set var="centerTotal" value="${centerTotal+i.cash+i.card}"/></c:otherwise>
				</c:choose>
			</c:when>
			<c:otherwise>
				<c:choose>
				<c:when test="${i.tab==0}"><c:set var="leftTotal" value="${leftTotal+i.cash+i.card}"/></c:when>
				<c:otherwise><c:set var="centerTotal" value="${centerTotal+i.cash+i.card}"/></c:otherwise>
				</c:choose>
			</c:otherwise>				
			</c:choose>				
			</c:forEach>				
				
				<tr class="_0">
					<td class="seq"><input type="checkbox" disabled="disabled" class="_0"/></td>
					<td class="yyyymmdd"><w:date /></td>
					<td class="description"></td>
					<td class="cash numbertd"></td>
					<td class="card numbertd disabled"></td>
					<td class="cardtype disabled"><span class="cardtype_0"></span></td>
					<td class="cate"><span class="cate_0">미분류</span></td>			
				</tr>				
			</tbody>
		</table>
		<table id="grid_over" cellpadding="0" cellspacing="0">
			<c:out value="${column}" escapeXml="false"/>
			<tbody>
				<tr>
					<c:forEach begin="0" end="6">
						<td></td>
					</c:forEach>					
				</tr>
			</tbody>
		</table>	
	</div>	
	

	<div id="contents_total" class="contents_total_${param.tab}">
	<table cellspacing="0" cellpadding="0">
	<tbody>
	<tr>
		<td style="width: 40%;" colspan="2">
			<button id="delBtn" class="ui-button ui-state-default ui-corner-all">선택삭제</button>
		</td>
		<td style="width: 15%;">
			<span class="label_area">현금
				<span class="separate_line">|</span>
			</span>
			<span id="cashTotal" class="value_area numberTotal">${cashTotal}</span>
		</td>
		<td style="width: 15%;">
			<span class="label_area">카드
				<span class="separate_line">|</span>
			</span>
			<span id="cardTotal" class="value_area numberTotal">${cardTotal}</span>
		</td>
		<td style="width: 20%; text-align: center;" rowspan="2">			
			<button id="saveBtn" class="ui-button ui-state-default ui-corner-all">저장하기</button>				
		</td>
	</tr>
	<tr>
		<c:set var="totalName" value="<%=totalName%>"/>
		<td style="width: 20%">
			<span class="left_total">${totalName[param.tab][0]}
				<span id="leftTotal" class="numberTotal">${leftTotal}</span>
			</span>
		</td>
		<td style="width: 20%">
			<span class="center_total">${totalName[param.tab][1]}
				<span id="centerTotal" class="numberTotal">${centerTotal}</span>
			</span>
		</td>
		<td colspan="2" style="width: 30%">
			<span class="right_total">${totalName[param.tab][2]}
				<span id="bothTotal" class="numberTotal">${cashTotal+cardTotal}</span>
			</span>
		</td>
	</tr>
	</tbody>
	</table>
	</div>
</div>

<script type="text/javascript">
tab = ${param.tab};
contentsInit();
</script>
